package net.tycmc.cty.ctyms.timejob.iems.job;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import net.tycmc.cty.ctyms.timejob.function.monitore.CheckSelfAndReport;
import net.tycmc.cty.ctyms.timejob.function.monitore.ControlHandler;
import net.tycmc.cty.ctyms.timejob.function.monitore.HeartBeat;
import net.tycmc.cty.ctyms.timejob.iems.service.AutoInstallVclService;

import org.apache.commons.configuration.ConfigurationException;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.tycmc.functions.util.DynamicReadConfig;

/**
 * 定时作业，用于统计终端自动安装拆除
 * @author liuhuanhuan
 *
 */
public class AutoInstallVclJob extends QuartzJobBean {
	private Map<String,Object> param;
	private AutoInstallVclService jobData;

	@Override
	protected void executeInternal(JobExecutionContext arg0)
			throws JobExecutionException {
		if(ControlHandler.isControl()){
			this.reportHeartBeat();
			this.checkSelf();
		}
		//统计自动安装拆除
		this.jobData.autoInstallVclService();
	}
	/**
	 * 上报心跳信号
	 **/
	private void reportHeartBeat() {
		HeartBeat hbeat = new HeartBeat();
		this.param = new HashMap<String,Object>();
		String autoInstallVcl = "1";
		try {
			autoInstallVcl = DynamicReadConfig.getConfigProperty("config.properties", "autoInstallVclKey");
		} catch (ConfigurationException e) {
			e.printStackTrace();
		}
		this.param.put("jobID", autoInstallVcl);
		this.param.put("jobName", "自动安装设备");
		hbeat.produceAndReportHeateBeat(this.param);
	}
	/**
	 * 自检，如果自检未通过则进行报警
	 **/
	private void checkSelf() {
		CheckSelfAndReport csar = new CheckSelfAndReport();
		csar.checkIfFailReport(this.param);
	}
	public AutoInstallVclService getJobData() {
		return jobData;
	}

	public void setJobData(AutoInstallVclService jobData) {
		this.jobData = jobData;
	}
}
